var express = require('express');
var router = express.Router();
var mysql = require('./mysqlServer');
var redis = require('./redisServer');

/* GET home page. */
router.get('/getList', function(req, res, next) {
	//redis.set('reidsTest', "hello world"); 
	redis.expire('reidsTest', 20);
	redis.get("reidsTest", function(err, reply) {
		var data = {
			code: 200,
			msg: reply
		}
		console.log("*****")
		console.log(reply)
	});
	mysql.getConnection(function(err, connection) {
		connection.query('select title from test', function(err, rows, fields) {
			if (err) {
				console.log(err);
			};
			var listArray = [];
			if (rows) {
				for (var i = 0; i < rows.length; i++) {
					listArray.unshift(rows[i]);
				}
				var json = {
					code: 200,
					data: listArray
				}
				res.send(json);
				connection.release();
			} else {
				var json = {
					data: "null"
				}
				res.send(json);
			}
		});
	});
});
module.exports = router;